<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    import="java.awt.Graphics2D"
    import="java.awt.image.renderable.ParameterBlock"
    import="java.awt.image.BufferedImage"
    import="javax.media.jai.JAI"
    import="javax.media.jai.RenderedOp"
    import="javax.imageio.ImageIO"
    import="com.oreilly.servlet.MultipartRequest"
    import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy"
    import="java.util.*"
    import="java.io.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Thumnail Image</title>
</head>
<body>

<%
	String imagePath=request.getRealPath("Img");
	int size = 1*1024*1024;
	String filename="";
	
	try{
		MultipartRequest multi = new MultipartRequest(request, imagePath, size, "UTF-8", new DefaultFileRenamePolicy());
		Enumeration files = multi.getFileNames();
		
		String file = (String)files.nextElement();
		filename = multi.getFilesystemName(file);
	}
	catch(Exception e){
		e.printStackTrace();
	}
	
	ParameterBlock pb = new ParameterBlock();
	pb.add(imagePath + "/" + filename);
	RenderedOp rOp = JAI.create("fileload", pb);
	
	BufferedImage bi = rOp.getAsBufferedImage();
	BufferedImage thumb = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
	
	Graphics2D g = thumb.createGraphics();
	g.drawImage(bi, 0, 0, 100, 100, null);
	
	File file = new File(imagePath + "/sm_" + filename);
	ImageIO.write(thumb, "jpg", file);
%>
	
-저장위치:<%=imagePath %><br>
-원본 이미지-<br>
<img src="../Img/<%=filename %>"><p>
-섬네일 이미지-<br>
<img src="../Img/sm_<%=filename %>">

</body>
</html>